package com.example.ssu_eduapp.page;

import java.util.ArrayList;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.example.ssu_eduapp.R;
import com.example.ssu_eduapp.R.id;
import com.example.ssu_eduapp.R.layout;
import com.example.ssu_eduapp.tools.BasePreference;
import com.example.ssu_eduapp.tools.LogUtils;

public class UniTalkRosterFragment extends Fragment{

	private Context mContext;

	private Spinner sp_status;

	private LogUtils log;

	private BasePreference bpref;
	
	public UniTalkRosterFragment(Context context) {
		mContext = context;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, 
			ViewGroup container, Bundle savedInstanceState) {

		View view = inflater.inflate(R.layout.fragment_roster, null);

		log = new LogUtils();

		sp_status = (Spinner) view.findViewById(R.id.sp_status);

		bpref = new BasePreference(getActivity());

		ArrayList<String> subjectList;

		subjectList = new ArrayList();

		subjectList.add("Online");
		subjectList.add("Away");
		subjectList.add("Extended Away");
		subjectList.add("Do not disturb");
		subjectList.add("Free for chat");
		subjectList.add("Offline");

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), 
				android.R.layout.simple_spinner_dropdown_item, subjectList); 
		sp_status.setAdapter(adapter);
		sp_status.setOnItemSelectedListener(spnCountriesListener); 


		return view;
	}

	public void setPreference(String name, Object value) {
		
		if (value instanceof String) {
			bpref.put(name, String.valueOf(value));
		} else if (value instanceof Integer) {
			bpref.put(name, Integer.parseInt(String.valueOf(value)));
		}
	
	}
	private Spinner.OnItemSelectedListener spnCountriesListener = 
			new Spinner.OnItemSelectedListener() { 
		public void onItemSelected(AdapterView parent, View v, int position, long id) { 
			log.i(parent.getSelectedItem().toString() + position);
			setPreference(BasePreference.PREF_CURRENTSELECTION, position);

		} 

		public void onNothingSelected(AdapterView parent) { }             
	}; 

}
